<template>
    <mi-form-page @submit="submit" v-loading="edit.loading">
        <el-form :model="edit.info"
                 ref="formRef"
                 :rules="rules">

            <el-form-item prop="goods_id" label="商品">
                <goods-select v-model="edit.info.goods_id" />
            </el-form-item>
            <el-form-item prop="avatar" label="会员头像">
                <up-avatar v-model="edit.info.avatar" />
            </el-form-item>
            <el-form-item prop="nickname" label="会员昵称">
                <mi-input v-model="edit.info.nickname" />
            </el-form-item>
            <el-form-item prop="goods_star" label="商品星级">
                <el-rate v-model="edit.info.goods_star"  score-template="{value} 分" />
            </el-form-item>
            <el-form-item prop="service_star" label="服务星级">
                <el-rate v-model="edit.info.service_star" score-template="{value} 分" />
            </el-form-item>
            <el-form-item prop="content" label="内容">
                <mi-input v-model="edit.info.content" type="textarea" :rows="3" />
            </el-form-item>
            <el-form-item prop="images" label="图片">
                <mi-up-images v-model="edit.info.images" />
            </el-form-item>
        </el-form>
    </mi-form-page>
</template>

<script setup lang="ts">
import {reactive, watch, ref, onBeforeMount, inject} from "vue";
import {makeModelAuth} from "@/utils/auth";
import List from "@/model/list";
import Edit from "@/model/edit";
import {FormInstance} from "element-plus";
import {simpleGet, simplePost} from "@/utils/request";
import {useAdminStore} from "@/store/admin";
import GoodsSelect from "@/views/store/components/GoodsSelect.vue";
import UpAvatar from "@/views/site/user/components/UpAvatar.vue";

const formRef = ref<FormInstance>()
const auth = makeModelAuth("store.goodsReply")
const rules = {
    title:[{required:true, message:'必填'}],
}
const adminStore = useAdminStore()
const list = inject<List>("list")
const edit = inject<Edit>("edit", new Edit({}))
const id = edit.info.id

const submit = () => {
    let url = '/' + (id ? auth.edit : auth.add)
    edit.submit({
        formRef: formRef.value,
        url: url,
        list: list
    })
}


onBeforeMount(() => {
    edit.init(async () => {
        if (id){
            // 请求表单数据
            let res = await simpleGet('/' + auth.edit, {id:id})
            edit.info = res.info
        }else{
            edit.info = {
                status:1,
            }
        }
    })
})

</script>

<style scoped>

</style>
